class StudentSearcheService {

    boolean transactional = false
    static scope = "session"

    def searchTimes = 0
    def name=""
    def sex=""
    def classes
    def level =""
    def school

    def searcheStudentInit(searchName,searchSex,searchLevel,searchClasses,searchSchool) {
        name = searchName
        sex = searchSex
        level = searchLevel
        classes = searchClasses
        school = searchSchool
        searchTimes++
    }

    def getSearchStudentName() {
        return name
    }

    def searchStudentList() {
        log.info("############")
        def c = Student.createCriteria()
        def results = c {
            if(name){
                 like ("name", "%"+name+"%")
            }
            if(level){
                 like("level", level)
            }
            if(sex){
                 like("sex", sex)
            }
            if(classes){
                 eq("classes", classes)
            }
            eq ("school" , school)
            eq ("state" , false)
        }
        def studentLevels = org.grails.plugins.lookups.Lookup.codeList("studentLevel")

        [studentInstanceList: results,
        studentLevels:studentLevels,
        name:name,
        level:level,
        sex:sex,
        classes:classes]
    
    }
}
